#!/bin/bash

# Test disk full handling

. ./common

_need_to_be_root

_make_device 0 $((1024 ** 3))
_make_device 1 $((1024 ** 3))
_make_device 2 $((30 * 1024 ** 2))
_make_device 3 $((30 * 1024 ** 2))

# create log files of sheep 2 and 3 on other places
touch $STORE/0/sheep2.log $STORE/0/sheep3.log
ln -s $STORE/0/sheep2.log $STORE/2/sheep.log
ln -s $STORE/0/sheep3.log $STORE/3/sheep.log

for i in `seq 0 3`; do
    _start_sheep $i
done

_wait_for_sheep 4

_cluster_format

# create two VDIs before there are enough spaces
$DOG vdi create test0 100M
$DOG vdi create test1 100M

# make sheep 0 and 1 disk full
dd if=/dev/zero of=$STORE/2/zero > /dev/null 2>&1
dd if=/dev/zero of=$STORE/3/zero > /dev/null 2>&1

# test data write against disk-full cluster
for i in `seq 0 10`; do
    echo $i | $DOG vdi write test0 $((i * 4 * 1024 * 1024)) 512 -p 7000
    echo $i | $DOG vdi write test1 $((i * 4 * 1024 * 1024)) 512 -p 7002
done

# test vdi creation against disk-full cluster
$DOG vdi create test2 100M -p 7000
$DOG vdi create test3 100M -p 7002

for i in `seq 0 3`; do
    $DOG node list -p 700$i
done
_node_info
ls $STORE/*/{obj,d[0-9]*}/* 2> /dev/null | \
	_filter_store | _filter_md_store | sort
